#include "link/include/client.h"
int client_init(int *sockfd,puser_t pusr)
{//功能待完善
    int fd=open("link/conf/config",O_RDONLY);
    ERROR_CHECK(fd,-1,"open");
    struct stat statbuf;
    fstat(fd,&statbuf);
    char buf[256]={0};
    read(fd,buf,statbuf.st_size+1);
    char ip[20]={0};
    char port[10]={0};
    int i=3,j=0;
    for(j=0;*(buf+i)!='\n';++i,++j)
    {
        *(ip+j)=*(buf+i);
    }
    i+=6;
    for(j=0;*(buf+i)!='\n';++i,++j)
    {
        *(port+j)=*(buf+i);
    }
    tcp_init(sockfd,ip,port);
    return 0;
}
int tcp_init(int *sockfd,char *ip,char *port)
{
    int ret=0;
    *sockfd=socket(AF_INET,SOCK_STREAM,0);
    ERROR_CHECK(*sockfd,-1,"socket");
    struct sockaddr_in ser;
    bzero(&ser,sizeof(ser));
    ser.sin_family=AF_INET;
    ser.sin_addr.s_addr=inet_addr(ip);
    ser.sin_port=htons(atoi(port));
    ret=connect(*sockfd,(struct sockaddr*)&ser,sizeof(ser));
    ERROR_CHECK(ret,-1,"connect");
    return 0;
}
